package com.muqi.app.qlearn.student.ui;

import java.util.HashMap;

import com.muqi.app.network.http.MyAsyncHttp;
import com.muqi.app.network.http.ParamsUtils;
import com.muqi.app.network.http.MyAsyncHttp.AsyncCallBackListener;
import com.muqi.app.network.http.MyAsyncHttp.RESULTCODE;
import com.muqi.app.project.contants.NetWorkApi;
import com.muqi.app.qlearn.student.BaseFragmentActivity;
import com.muqi.app.qlearn.student.R;


import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class JuBaoActivity extends BaseFragmentActivity {

	private EditText ping_lun_shu_ru;
	private TextView pinlun_quxiao, ping_lun_fa_song;
	private String content;
	private String recordId;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ju_bao);
	}

	public void PostevaluateHttp() {
		content = ping_lun_shu_ru.getText().toString();
		if (content == null || content.length() <= 0) {
			   Toast.makeText(this, "请输入内容", Toast.LENGTH_SHORT).show();
		}else{
			jubao(content);
		}

	}
	/**
	 * 举报
	 */
	protected void jubao(String content) {
		HashMap<String, Object> sendMap = new HashMap<String, Object>();
		sendMap.put("token", mSpUtil.getToken());
		sendMap.put("id", recordId);
		sendMap.put("content", content);
		String requestUrl = ParamsUtils.buildParams(NetWorkApi.JUBAO_API,
				sendMap);
		MyAsyncHttp.get(this, requestUrl, new AsyncCallBackListener() {

			@Override
			public void onAsyncCallBack(RESULTCODE resuleCode, String request,
					String result) {
				Log.e("===", result);
				if (resuleCode == RESULTCODE.SUCCESS) {
					Toast.makeText(JuBaoActivity.this, "举报成功",
							Toast.LENGTH_SHORT).show();
					setResult(RESULT_OK);
					finish();

				}
			}
		});

	}

	@Override
	protected void onInit() {

		pinlun_quxiao = (TextView) findViewById(R.id.pinlun_quxiao);
		ping_lun_fa_song = (TextView) findViewById(R.id.ping_lun_fa_song_post);
		ping_lun_shu_ru = (EditText) findViewById(R.id.ping_lun_shu_ru);

		pinlun_quxiao.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				onBackPressed();
			}
		});

		ping_lun_fa_song.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				PostevaluateHttp();
			}
		});

	}

	@Override
	protected void onData() {
		recordId=getIntent().getStringExtra("recordId");
		
	}

}
